'use strict';

module.exports = {
  getToken(value, options) {
    return 'Bearer ' + this.app.jwt.sign(value, this.app.config.jwt.secret, options);
  },
  // 验证token
  checkToken(token) {
    let res = '';
    const result = this.app.jwt.verify(token, this.app.config.secret) || {};
    const {
        exp,
      } = result,
      current = Math.floor(Date.now() / 1000);
    if (current <= exp) {
      res = {
        id: result.id,
        contact: result.contact,
      } || {};
    }
    return res;
  },
};

